#include <stdio.h>
#include <stdlib.h>
const char* file_name="student_data.txt";
typedef struct  Student{
	char name[20];
	int age;
	int class;
	double height;
}Student;
#define MAX_N 10000
Student stu_arr[MAX_N+5];
int stu_cnt;

void list_student(){
	int len=printf("%4s|%10s|%4s|%6s|%7s|","id","name","age","class","height");
	printf("\n");
	for(int i=0;i<len;i++)
		printf("=");
	printf("\n");
	for(int i=0;i<stu_cnt;i++){
		printf("%4d|%10s|%4d|%6d|%7.2f|\n",i,
			stu_arr[i].name,
			stu_arr[i].age,
			stu_arr[i].class,
			stu_arr[i].height
			);
	}
		
	return ;
}


enum NO_TYPE{
	LIST,
	ADD,
	MODIFY,
	DELETE,
	QUIT
};

int read_from_file(Student* arr){
	int i=0;
	FILE *fp=fopen(file_name,"r");
	if(fp==NULL) return 0;
	while(fscanf(fp,"%s",arr[i].name)!=EOF)
	{
		fscanf(fp,"%d%d%lf",
			&arr[i].age,
			&arr[i].class,
			&arr[i].height
			);
		i+=1;
	}}
int usage(){
	int no;
	do{
	printf("%d:list students\n",LIST);
	printf("%d:add a new student\n",ADD);
	printf("%d:modify a student\n",MODIFY);
	printf("%d:deletea student\n",DELETE);
	printf("%d:quit\n",QUIT);
	printf("mysql>");
	scanf("%d",&no);
	}while(no<1||no>5);
	return no;
}
int main()
{
	stu_cnt=read_from_file(stu_arr);
	while(1){
		int no=usage();	
		switch(no){
		case LIST:printf("list students\n");
			list_student();
			break;
		case ADD:printf("add a new student\n");break;
		case MODIFY:printf("modify a student\n");break;
		case DELETE:printf("deletea student\n");break;
		case QUIT:printf("quit\n");
				exit(0);
		}
	}
	
	return 0;
}
